﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Text;
using Chenxin.Lib.Utility;

public partial class ShowDetailPreliminary : PageBase
{
    string strRecordId = string.Empty;

    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (string.IsNullOrEmpty(Request.Params["RecordId"]))
            {
                Response.Redirect("~/page/errorpage.aspx?msg=非法信息", true);
            }
            if (!IsPostBack)
            {
                strRecordId = Request.Params["RecordId"].ToString().Trim();
                this.hidRecordId.Value = strRecordId;
                Chenxin.Lib.Business.Entity.t_Preliminary_BaseInfo model = Chenxin.Lib.Business.DAL.t_Preliminary_BaseInfo.GetModel(new Guid(strRecordId));
                BindPreliminaryTable(model);
            }
        }
        catch (Exception ex)
        {
            //Url参数出错，页面跳转
            Response.Redirect("~/page/errorpage.aspx?msg=" + Server.UrlEncode(ex.Message) + "", true);
        }
    }

    private void BindPreliminaryTable(Chenxin.Lib.Business.Entity.t_Preliminary_BaseInfo model)
    {
        StringBuilder sb = new StringBuilder();

        //预审详情-房源信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\" style='text-align:center;'><span>预审信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">房源地址：</th><td>{0}</td><th style=\"text-align:right;\">房源编号：</th><td>{1}</td>", model.Address, model.HouseCode);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">建筑类型：</th><td>{0}</td><th style=\"text-align:right;\">建筑面积：</th><td>{1} ㎡</td>", model.BuildingType, model.BuildingArea);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">楼层：</th><td style=\"width:300px;\">{0}楼</td><th style=\"width:100px;text-align:right;\">竣工时间：</th><td>{1}年</td>", model.Total_Floor,model.CompleteYear);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">房源所属部门：</th><td>{0}</td><th style=\"text-align:right;\">房源所属人：</th><td>{1}</td>", model.EmpDepartName, model.EmployeeName);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">联系电话：</th><td>{0}</td><th style=\"text-align:right;\">成交总价：</th><td>{1}</td>", model.EmpPhone, model.SalePrice_T);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">申请部门：</th><td>{0}</td><th style=\"text-align:right;\">申请人：</th><td>{1}</td>", model.AppDepartName, model.AppEmployeeName);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">贷款类型：</th><td>{0}</td><th style=\"text-align:right;\">贷款总额：</th><td>{1}</td>", model.LoanInfo, model.LoanTotalMoney);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //预审详情-买受方信息Table
        string strWhere = string.Format("MainId = '{0}'", model.RecordId);
        DataSet ds = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo1.GetList(strWhere);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>贷款人信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr><th style='text-align:center;'>姓名</th><th style='text-align:center;'>身份证</th><th style='text-align:center;'>公积金账号</th><th style='text-align:center;'>配偶姓名</th><th style='text-align:center;'>配偶身份证</th><th style='text-align:center;'>配偶公积金</th></tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td style=\"width:100px;text-align:center;\">{0}</td><td style=\"width:155px;text-align:center;\">{1}</td><td style=\"width:155px;text-align:center;\">{2}</td>", dr["CustomerName"], dr["IDNum"], dr["GJJNum"]);
                sb.AppendFormat("<td style=\"width:100px;text-align:center;\">{0}</td><td style=\"width:155px;text-align:center;\">{1}</td><td style=\"text-align:center;\">{2}</td>", dr["SpousesName"], dr["SpousesIDNum"], dr["SpousesGJJNum"]);
                sb.Append("</tr>");
            }
        }
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">特殊情况说明：</th><td colspan=\"5\" style=\"width:185px\">{0}</td>", model.SpecialExp);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //预审详情-出售方信息Table
        ds = null;
        ds = Chenxin.Lib.Business.DAL.t_Preliminary_SubInfo2.GetList(strWhere);
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"4\" style='text-align:center;'><span>出售方信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr><th style='text-align:center;'>姓名</th><th style='text-align:center;'>身份证</th><th style='text-align:center;'>配偶姓名</th><th style='text-align:center;'>配偶身份证</th></tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<td style=\"width:100px;text-align:center;\">{0}</td><td style=\"width:310px;\">{1}</td>", model.SaleName, model.SaleIDCard);
        sb.AppendFormat("<td style=\"width:100px;text-align:center;\">{0}</td><td style=\"width:310px;\">{1}</td>", model.SaleSpouseeName, model.SaleSpouseeIDCard);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">剩余贷款：</th><td>{0}</td><th style=\"text-align:right;\">原贷款额：</th><td>{1}</td>", model.OldRestMoney, model.OldLoanMoney);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">原贷款银行：</th><td colspan=\"3\">{0}</td>", model.OldLoanBank);
        sb.Append("</tr>");
        sb.Append("<tr><th colspan=\"2\" style='text-align:center;'>共有人姓名</th><th colspan=\"2\" style='text-align:center;'>共有人身份证</th></tr>");
        if (ds != null && ds.Tables[0].Rows.Count != 0)
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                sb.Append("<tr>");
                sb.AppendFormat("<td colspan=\"2\">{0}</td><td colspan=\"2\">{1}</td>", dr["SaleNamePublic"], dr["SaleIDCardPublic"]);
                sb.Append("</tr>");
            }
        }
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //预审详情-预审回复信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>预审回复信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">评估价：</th><td>{0}</td><th style=\"text-align:right;\">建议贷款银行：</th><td>{1}</td>", model.EstimatePrice, model.ProposeBank);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">公积金贷款金额：</th><td>{0}万元</td><th style=\"text-align:right;\">公积金贷款年限：</th><td>{1}年</td>", model.GJJmoney, model.GJJyear);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">商业贷款金额：</th><td style=\"width:300px;\">{0}万元</td><th style=\"width:100px;text-align:right;\">商业贷款年限：</th><td>{1}年</td>", model.SYMoney, model.SYYear);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">预审回复人：</th><td>{0}</td><th style=\"text-align:right;\">预审回复时间：</th><td>{1}</td>", model.ReplyUserName, model.ReplyPreliminaryDate);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"text-align:right;\">预审意见：</th><td id=\"se1\" colspan=\"2\" style=\"width:185px\">{0}</td><td><input type=\"button\" onclick=\"select_all('se1')\" value=\"复制预审意见\"/></td>", model.ReplyAdivce);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //预审详情-预约贷款信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>预约贷款信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">预约贷款时间：</th><td style=\"width:300px;\">{0}</td><th style=\"width:100px;text-align:right;\">签约地点：</th><td>{1}</td>", model.LoanApplyDate, model.OrderPlace);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        //预审详情-预约回复信息Table
        sb.Append("<table width=\"100%\" cellspacing=\"1\" class=\"tabsorternew table_archive\">");
        sb.Append("<thead>");
        sb.Append("<tr>");
        sb.Append("<th colspan=\"6\" style='text-align:center;'><span>预约回复信息</span></th>");
        sb.Append("</tr>");
        sb.Append("</thead>");
        sb.Append("<tbody>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">签约银行：</th><td>{0}</td>", model.OrderBank);
        sb.Append("</tr>");
        sb.Append("<tr>");
        sb.AppendFormat("<th style=\"width:100px;text-align:right;\">备注：</th><td>{0}</td>", model.OrderBeiZhu);
        sb.Append("</tr>");
        sb.Append("</tbody>");
        sb.Append("</table>");
        sb.Append("<div class=\"clear\" style=\"height:10px\"></div>");

        sb.Append("<div style=\"text-align:center\"><a href='#' title='关闭' id='aClose'><span>关闭</span></a></div>");
        this.ltPreliminaryDetailInfo.Text = sb.ToString();
    }
}
